/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.svs.framework.base.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.svs.common.base.BaseEntity;
import com.svs.framework.base.dao.CrudDao;

/**
 * Service基类
 * 
 * @author dujianqiao
 * @version 2018-11-19
 */
@Transactional
public abstract class CrudService<D extends CrudDao<T>, T extends BaseEntity<T>> extends BaseService {

	/**
	 * 持久层对象
	 */
	@Autowired
	protected D dao;

	/**
	 * 获取单条数据
	 * 
	 * @param id
	 * @return
	 */

	public T selectByPrimaryKey(Long id) {
		return dao.selectByPrimaryKey(id);
	}

	/**
	 * 获取单条数据
	 * 
	 * @param id
	 * @return
	 */
	public T selectByPrimaryKey(String id) {
		return dao.selectByPrimaryKey(id);
	}
	

	/**
	 * 查询列表数据
	 * 
	 * @param entity
	 * @return
	 */
	public List<T> selectAllList(T entity) {
		return dao.selectAllList(entity);
	}

	/**
	 * 保存数据（插入或更新）
	 * 
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public int save(T entity) {
		return dao.insertSelective(entity);
	}

	/**
	 * 保存数据（插入或更新）
	 * 
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public int update(T entity) {
		return dao.updateByPrimaryKeySelective(entity);
	}
	
	/**
	 * 删除数据
	 * 
	 * @param id
	 */
	@Transactional(readOnly = false)
	public int deleteByPrimaryKey(Long id) {
		return dao.deleteByPrimaryKey(id);
	}
	
	/**
	 * 删除数据
	 * 
	 * @param id
	 */
	@Transactional(readOnly = false)
	public int deleteByPrimaryKey(String id) {
		return dao.deleteByPrimaryKey(id);
	}
	
	/**
	 * 删除数据
	 * 
	 * @param id
	 */
	@Transactional(readOnly = false)
	public int deleteByPrimaryKeys(String[] id) {
		return dao.deleteByPrimaryKeys(id);
	}


}
